package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.TReason;
import com.ruoyi.system.service.ITReasonService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 会计项目原因Controller
 * 
 * @author ruoyi
 * @date 2022-03-17
 */
@RestController
@RequestMapping("/system/reason")
public class TReasonController extends BaseController
{
    @Autowired
    private ITReasonService tReasonService;

    /**
     * 查询会计项目原因列表
     */
    @GetMapping("/list")
    public TableDataInfo list(TReason tReason)
    {
        startPage();
        List<TReason> list = tReasonService.selectTReasonList(tReason);
        return getDataTable(list);
    }
    @GetMapping("/listRC")
    public TableDataInfo listReason(TReason tReason)
    {
        startPage();
        List<TReason> list = tReasonService.selectTReason(tReason);
        return getDataTable(list);
    }

    /**
     * 导出会计项目原因列表
     */
    @PostMapping("/export")
    public void export(HttpServletResponse response, TReason tReason)
    {
        List<TReason> list = tReasonService.selectTReasonList(tReason);
        ExcelUtil<TReason> util = new ExcelUtil<TReason>(TReason.class);
        util.exportExcel(response, list, "会计项目原因数据");
    }

    /**
     * 获取会计项目原因详细信息
     */
    @GetMapping(value = "/{rid}")
    public AjaxResult getInfo(@PathVariable("rid") Long rid)
    {
        return AjaxResult.success(tReasonService.selectTReasonByRid(rid));
    }

    /**
     * 新增会计项目原因
     */

    @PostMapping
    public AjaxResult add(@RequestBody TReason tReason)
    {
        return toAjax(tReasonService.insertTReason(tReason));
    }

    /**
     * 修改会计项目原因
     */

    @PutMapping
    public AjaxResult edit(@RequestBody TReason tReason)
    {
        return toAjax(tReasonService.updateTReason(tReason));
    }

    /**
     * 删除会计项目原因
     */

	@DeleteMapping("/{rids}")
    public AjaxResult remove(@PathVariable Long[] rids)
    {
        return toAjax(tReasonService.deleteTReasonByRids(rids));
    }
}
